<template>
  <view class='analyze_item'>
    <view class='title_box' v-if='title_show'>
      <text>{{content.reportName}}</text>
      <view class='icon_box' @tap.stop='del'>
        <text class='iconfont icon-shanchu'></text>
      </view>
    </view>
    <view v-if="version_arr.length != 0">
      <view class='card' v-for='(version,v_index) in version_arr' :key='v_index' @tap='openDet(version)'>
        <view class='card_title'>
          <view class='card_title_box'>
            <text>V{{version.version}}</text>
            <view class='status' v-if="version.status == 0">等待分析</view>
            <view class='status' v-if="version.status == 1">分析中</view>
            <view class='status status1' v-if="version.status == 2">分析完成</view>
            <view class='status status2' v-if="version.status == 3">已删除</view>
          </view>
          <!-- 停止按钮 弃用 -->
          <view class='stop_btn' hover-class='btn_hover2' v-if="false">停止</view>
        </view>
        <view class='time_info'>
          <view>时间范围：<text>{{version.startTime}} 至 {{version.endTime}}</text></view>
          <view>创建时间：<text>{{version.updateOn}}</text></view>
          <view v-if="version.report != null">数据总量：<text>{{version.report.total}}</text></view>
        </view>
        <view class='data_info' v-if="version.report != null">
          <view v-for='(source,s_index) in version.report.source' :key='s_index'>
            <view>{{convert(source.sourcetype)}}：<text>{{source.hot}}</text></view>
          </view>
        </view>
        <view class='look' v-if='!title_show' @tap='openDet(version)'>查看 V{{version.version}}分析报告</view>
      </view>
    </view>
      
      <view class='card_btn_box' v-if='title_show'>
        <button 
          class='btn' 
          hover-class='btn_hover2'
          :class='{btn_disabled: title_show && left_disabled }' 
          @tap.stop='clickLeftBtn'
        >{{left_btn_text}}</button>
        <button 
          class='btn'
          hover-class='btn_hover2' 
          :class='{btn_disabled:right_disabled}' 
          @tap.stop='clickRightBtn'
        >{{right_btn_text}}</button>
      </view>

  </view>
</template>

<script>
  export default {
    props: {
      content: {
        type: Object,
        default() {
          return {}
        }
      },
      content2: {
        type: Array,
        default() {
          return []
        }
      },
      title_show: {
        type: Boolean,
        default: true
      },
      right_disabled: {
        type: Boolean,
        default: false
      },
      left_btn_text: {
        type: String,
        default: "更新报告"
      },
      right_btn_text: {
        type: String,
        default: "查看历史"
      },
    },
    data() {
      return {
        version_arr: [],
        left_disabled: false,
        convert: this.$convert
      }
    },
    watch: {
      content(val) {
        this.version_arr = [];
        this.version_arr.push(val.result[val.result.length-1]);
      }
    },
    mounted() {
      if(this.title_show) {
        this.version_arr = [];
        this.version_arr.push(this.content.result[this.content.result.length-1]);
      }else {
        this.version_arr = this.content2
      }
      
      this.$nextTick(() => {
        let status = this.version_arr[0].status;
        if(this.version_arr.length != 0 &&  status == 0 || status == 1) {
          this.left_disabled = true
        }
      })
    },
    methods: {
      // 打开详情
      openDet(version) {
        uni.navigateTo({
          url: '/pages/analyze/analyzeDet/index?eventId='+version.eventId+'&startTime='+version.startTime
        });
      },
      // 点击删除
      del() {
        this.$emit("delete")
      },
      // 点击左边按钮
      clickLeftBtn() {
        this.$emit("clickLeftBtn")
      },
      // 点击右边按钮
      clickRightBtn() {
        this.$emit("clickRightBtn")
      },
    }
  }
</script>

<style lang="scss" scoped>
  .analyze_item {
    width: 100%;
    background: #fff;
    border-radius: 12upx;
    .title_box {
      width: 100%;
      height: 90upx;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding-left: 23upx;
      box-sizing: border-box;
      font-size: 30upx;
      color: #333;
      font-weight: 600;
      border-bottom: 1px solid #eee;
      .icon_box {
        width: 100upx;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        .iconfont {
          font-size: 35upx;
          color: #999;
          font-weight: 500;
        }
      }
      
    }
    .card {
      width: 100%;
      padding: 23upx;
      box-sizing: border-box;
      .card_title {
        width: 100%;
        padding-bottom: 20upx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        &_box {
          flex: 1;
          display: flex;
          align-items: center;
          justify-content: flex-start;
          >text {
            font-size: 30upx;
            color: #333;
            font-weight: 600;
          }
          .status {
            height: 30upx;
            background: #2191FF;
            font-size: 20upx;
            padding: 10upx 20upx;
            box-sizing: border-box;
            white-space: nowrap;
            color: #fff;
            border-radius: 6upx;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-left: 20upx;
          }
          .status1 {
            background: #1BBF00;
          }
          .status2 {
            background: #D40E00;
          }
        }
        .stop_btn {
          width: 100upx;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: flex-end;
          font-size: 30upx;
          color: #0084FF;
        }
      }
      .time_info {
        width: 100%;
        >view {
          color: #999;
          font-size: 24upx;
          margin-bottom: 25upx;
          &:nth-last-child(1) {
            margin: 0;
          }
          >text {
            color: #333;
          }
        }
      }
      .data_info {
        width: 100%;
        border-radius: 6upx;
        background: #F7F7F7;
        padding: 30upx 30upx 10upx;
        box-sizing: border-box;
        margin-top: 25upx;
        >view {
          width: 33.333%;
          display: inline-block;
          >view {
            color: #999;
            font-size: 24upx;
            margin-bottom: 25upx;
            >text {
              color: #333;
            }
          }

        }
      }
      .look {
        width: 100%;
        height: 80upx;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 30upx;
        color: #333;
        border: 1px solid #eee;
        border-radius: 10upx;
        box-sizing: border-box;
        margin-top: 10upx;
      }
    }
    .card_btn_box {
      width: 100%;
      height: 90upx;
      display: flex;
      overflow: hidden;
      border-radius: 0 0 12upx 12upx;
      border-top: 1px solid #eee;
      >button {
        width: 50%;
        height: 100%;
        border-radius: 0;
        background: #fff;
        color: #333;
        &:nth-child(1) {
          border-right: 1px solid #eee;
          box-sizing: border-box;
        }
      }
      .btn_disabled {
        color: #ccc
      }
    }

  }
</style>